<template>
  <div class="center_attention_container">
    <div class="attention_list" v-for="item in author_concern" :key="item.id">
      <!-- 用户头像 -->
      <div class="attention_avatar">
        <img v-lazy="item.profile" class="img-fluid w-100 h-100" alt="" />
      </div>
      <!-- 用户信息 -->
      <div class="attention_userInfo">
        <div class="infoBox">
          <div
            class="attention_userInfo_title"
            @click="toPeopleCenter(item.id)"
          >
            {{ item.nickName | uncodeUtf16 }}
          </div>
          <div class="attention_userInfo_description" v-if="item.description">
            {{ item.description | uncodeUtf16 }}
          </div>
        </div>
        <div class="attention_userInfo_baseinfo">
          <span class="article"
            >{{ JSON.parse(item.article)?.content.length || 0 }}文章</span
          >
          <span class="concern">
            {{ JSON.parse(item.concern)?.content.length || 0 }}关注
          </span>
          <span class="fans">
            {{ JSON.parse(item.fans)?.content.length || 0 }}粉丝
          </span>
        </div>
      </div>
      <!-- 私信和关注 -->
      <div
        class="attention_tools"
        v-if="type === 'concern' && userInfo.id === aimUserInfo.id"
        @click="cancelConcern(item.user_id)"
      >
        <div class="concern">
          <a href="javascript:;"
            ><span class="cancel2">取消关注</span
            ><span class="cancel">取关</span></a
          >
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";

export default {
  name: "CenterAttention",
  props: ["author_concern", "type"],
  computed: {
    ...mapState("user", ["userInfo", "aimUserInfo"]),
  },
  methods: {
    toPeopleCenter(id) {
      this.$parent.$parent.aimId = id;
      this.$parent.$parent.active = 0;
      this.$router.push(`/center/${id}`);
    },
    // 取关
    cancelConcern(author_id) {
      this.$parent.$parent.$parent
        .toolRequest("guan", 1, author_id, this.userInfo.user_id)
        .then(() => {
          // 将数据修改使监听数据发生改变，则刷新我的关注区域
          this.$parent.author_concern = [];
          if (this.$parent.pagina.total - 1 === 0) {
            this.$parent.pagina.total = 0;
            if (!this.$parent.pagina.total) {
              this.$parent.contentLength = true;
            }
          }
          this.$message({
            type: "success",
            message: "取关成功!",
          });
        });
    },
  },
  mounted() {
    // 关闭加载loading
    this.$parent.$parent.$parent.loadingResource = false;
    if (!this.$parent.pagina.total) {
      this.$parent.contentLength = true;
    }
  },
};
</script>

<style lang="less" scoped>
.center_attention_container {
  text-align: left;
  .attention_list {
    position: relative;
    display: flex;
    min-height: 132px;
    padding: 16px;
    border-bottom: var(--main-border-bottom);
    .attention_avatar {
      flex: auto;
      min-width: 100px;
      max-width: 100px;
      height: 100px;
      border-radius: 6px;
      overflow: hidden;
    }
    .attention_userInfo {
      display: flex;
      justify-content: space-between;
      flex-direction: column;
      margin-left: 20px;
      .attention_userInfo_title {
        /* 省略号 */
        text-overflow: -o-ellipsis-lastline;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 1;
        line-clamp: 1;
        -webkit-box-orient: vertical;
        max-width: 712px;
        font-size: 18px;
        transition: color 0.4s;
        cursor: url("@/assets/mouse/x2.cur"), auto !important;
        &:hover {
          color: var(--a-button-hover-color);
        }
      }
      .attention_userInfo_description {
        margin-top: 4px;
        color: #323232;
        font-size: 12px;
        height: 36px;
        flex: auto;
        max-width: 712px;
        /* 省略号 */
        text-overflow: -o-ellipsis-lastline;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        -webkit-box-orient: vertical;
      }
      .attention_userInfo_baseinfo {
        display: flex;
        span {
          color: #323232;
          font-size: 12px;
          margin-right: 6px;
        }
      }
    }
    .attention_tools {
      position: absolute;
      right: 16px;
      top: 16px;
      .concern {
        background: rgba(255, 255, 255, 0);
        border: 1px solid var(--a-button-hover-color);
        color: var(--a-button-hover-color);
        width: 82px;
        height: 36px;
        border-radius: 6px;
        font-size: 12px;
        a {
          width: 100%;
          height: 100%;
          text-align: center;
          line-height: 36px;
          display: block;
        }
        & a:hover {
          color: var(--a-button-hover-color) !important;
        }
      }
    }
  }
  .cancel {
    display: none;
  }
  .cancel2 {
    display: block;
  }
}
</style>